<route lang="json5">
  {
    style: {
      navigationBarTitleText: '',
      navigationBarBackgroundColor: '#ff6b6b',
      navigationBarTextStyle: 'black',
    },
  }
  </route>
<template>
  <view class="share-page">
 

    <!-- 主体内容 -->
    <view class="content">
      <view class="title">邀好友 收益赚不停</view>
      <view class="qr-box">
        <image class="qr-code" :src="qrCodeUrl" mode="aspectFit" />
      </view>
      <view class="invite-code">
        <text class="code-text">{{ inviteCode }}</text>
        <uni-icons type="redo" size="20" color="#FF6B6B" @click="handleCopy" />
      </view>
      <text class="code-label">我的邀请码</text>
    </view>

  
  </view>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { useUserStore } from '@/store'
import { postUserDetailAPI } from '@/service/index/index'
const userStore = useUserStore()

const qrCodeUrl = ref('' )

const inviteCode = ref('')
 

const handleCopy = () => {
  uni.setClipboardData({
    data: inviteCode.value,
    success: () => {
      uni.showToast({
        title: '复制成功',
        icon: 'success',
      })
    },
  })
}

 

const getUserInfo = () => {
  postUserDetailAPI({}).then(res => {
    console.log(res)
    if(res.code==1){
      qrCodeUrl.value = res.data.userinfo?.erweima
      inviteCode.value = res.data.userinfo?.erweima_code
      console.log(qrCodeUrl.value,inviteCode.value)
    }
  })
}
//#ifdef H5
onMounted(() => {
  console.log('userStore.userInfo.token',userStore.userInfo.token)
  if(userStore.userInfo.token){
    getUserInfo()
  }else{
    console.log('没有token')
    uni.navigateTo({
      url: '/pages/login/login'
    })
  }
})
//#endif
//#ifdef APP-PLUS||MP-WEIXIN
onLoad(() => {  
  console.log('onLoad')
  if(userStore.userInfo.token){
    getUserInfo()
  }else{
    uni.navigateTo({
      url: '/pages/login/login'
    })
  }
})

//#endif
onShow(() => {
  if(userStore.userInfo.token){
    getUserInfo()
  }else{
    uni.navigateTo({
      url: '/pages/login/login'
    })
  }
})
</script>

<style>
page {
  height: 100%;
}

.share-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: linear-gradient(180deg, #ff6b6b 0%, #ffa26b 100%);
}

.nav-bar {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  height: 88rpx;
  padding: 0 32rpx;
  background: transparent;
}

.nav-left {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48rpx;
  height: 48rpx;
}

.nav-title {
  flex: 1;
  font-size: 18px;
  font-weight: 500;
  color: #ffffff;
  text-align: center;
}

.content {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  padding: 60rpx 32rpx;
}

.title {
  margin-bottom: 80rpx;
  font-size: 40px;
  font-weight: bold;
  color: #ffe66d;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.qr-box {
  width: 400rpx;
  height: 400rpx;
  padding: 20rpx;
  margin-bottom: 40rpx;
  background: #ffffff;
  border-radius: 20rpx;
  box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.1);
}

.qr-code {
  width: 100%;
  height: 100%;
}

.invite-code {
  display: flex;
  align-items: center;
  padding: 20rpx 40rpx;
  margin-bottom: 16rpx;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 40rpx;
}

.code-text {
  margin-right: 20rpx;
  font-size: 32px;
  font-weight: bold;
  color: #ff6b6b;
}

.code-label {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.9);
}

.tab-bar {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-around;
  height: 100rpx;
  background: #ffffff;
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.tab-text {
  margin-top: 8rpx;
  font-size: 12px;
  color: #999999;
}

.tab-text.active {
  color: #ff6b6b;
}
</style>
